<?php
namespace app\parks\controller;
use app\common\controller\HomeCommon;
use think\Request;
use app\parks\model\Parks;

/**
 * 
 * @author admin
 *
 */
class Index extends HomeCommon
{
    public function index()
    {
    }
    /**
     * 园区列表
     */
    public function getlists(){
    	if(Request::instance()->isPost()){
    		
    		$keyword=empty(input('keyword'))?'':input('keyword');
    		$lat=empty(input('lat'))?'':input('lat');
    		$lng=empty(input('lng'))?'':input('lng');
    		
    		
                		
    		$where=" 1=1 and status=1 ";
    		if($keyword){
    			$where.=" and park_name like '%$keyword%'";
    		}
    		$order="id desc";
    		$field="id,park_name,logo,members_num";
    		if($lat && $lng){
    			$juli_str=juli_str($lat,$lng);
    			$field="id,park_name,logo,members_num,$field";
    			$order=" juli asc,id desc ";
    		}
    		
    		$list=db('parks')->field($field)->where($where)->order($order)->paginate();
    		return json(['errcode'=>'0','msg'=>'获取成功！','data'=>$list]);
    	}
    }
    /**
     * 获得当前最近园区
     * @return \think\response\Json
     */
    public function get_current_park(){
    	if(Request::instance()->isPost()){
    		$lat=input('lat');
    		$lng=input('lng');
    		$where=" 1=1 and status=1 ";
    		
    		if($lat && $lng){
    			$juli_str=juli_str($lat,$lng);
    			$order=" juli asc,id desc ";
    			$info=db('parks')->field("id,park_name,logo,$juli_str")->where($where)->order($order)->find();
    			return json(['errcode'=>'0','msg'=>'获取成功！','data'=>$info]);
    		}else{
    			return json(['errcode'=>'10001','msg'=>'经纬度参数错误！','data'=>[]]);
    		}
    		
    		
    		
    	}
    }
    
   
   
}
